#include <stdio.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <string.h>


int main()
{

	key_t key;
	int shmid;
	char* buf;

	//key值
	key = ftok("test", 100);
	if(key < 0)
	{
		perror("ftok");

	}
	printf("key = %d\n", key);

	//创建共享内存
	shmid = shmget(key, 64, IPC_CREAT|0666);
	if(shmid < 0)
	{
		perror("shmget");
	}
	printf("shmid = %d\n",shmid);

	//映射共享内存
	buf = shmat(24, NULL, 0);
	if( buf < 0)
	{
		perror("shmat");
	}

	strcpy(buf, "xiaoyang");



}
